<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>arttemply中的each的使用</title>
  <script src="template-web.js"></script>
</head>
<body>
  <table border="1" width="400px">
    <thead>
      <tr>
        <th>序号</th>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>性别</th>
      </tr>
    </thead>
    <tbody>
        <!-- <tr>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
        </tr> -->
    </tbody>
  </table>
  <script type="text/html" id="tpl">
    {{each data value index}}
    <tr>
        <td>{{index + 1}}</td>
        <td>{{value.id}}</td>
        <td>{{value.name}}</td>
        <td>{{value.age}}</td>
        <td>{{value.gender}}</td>
      </tr>
    {{/each}}
  </script>
  <script>
    var obj = {
      code: 200,
      data:[
        {id:1,name:'zs',age:20,gender:'女'},
        {id:2,name:'ls',age:21,gender:'女'},
        {id:3,name:'ww',age:20,gender:'男'},
        {id:4,name:'zl',age:23,gender:'女'},
        {id:5,name:'tq',age:25,gender:'男'},
      ],
    };
    var str = template('tpl',obj);
    document.querySelector('tbody').innerHTML = str;
  </script>
</body>
</html>